//  Created by <Omar MALAGOUEN>

//  Copyright 2011 All rights reserved.
//

/*
 * Various utilities for command line tools
 * Copyright (c) 2000-2010 Omar Malagouen
 *
 * This file is part of Kakola.
 *
 * Kakola is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * Kakola is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with Kakola; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#ifndef VIDEOFILE_H
#define VIDEOFILE_H

#include <QtGui/QMainWindow>
#include <QMessageBox>
#include <QFileDialog>
#include <QProcess>
#include <QThread>
#include <QTextStream>
#include <QFile>
#include <QStandardItemModel>
#include <QDoubleSpinBox>
#include <QTableWidgetItem>
#include <QItemDelegate>
#include <QProgressBar>
#include <QListWidget>
#include <QDateTime>
#include <QComboBox>
#include "cprofile.h"
#include "cdialogeventname.h"
#include <QCoreApplication>

class CVideoFile
{
public:
    CVideoFile();
    ~CVideoFile();

public:
    QDateTime lastModified;
    int status; // 99999 = In progress ; 2 = Already done ; 4 = Not started ; 0 = done
    QString input;
    int session;

    QString srcFileExtension; // Extension of src file, can be empty Ex : /tmp/toto , /home/
    QString cleanSrcFilePath; // if it's a directory we remove the last / ex: /home
    QString fileName; // /home/om => om , /usr/bin/ls => ls , /home/om/ => ""
    QString srcCompleteBaseName; // fileName without extension
    QString dstCompleteBaseName; // fileName without extension
    QString destFileSrt;
    QString srcFileSrt;
    QString destFileName;
    QString srcDirName; // C/:temp/toto.avi => C:/temp
                        // C:/Temp/toto/ => C:/Temp/toto
    QString dstDirName;
    QString srcUpDirName; // C/:temp/toto.avi => C:/temp
                        // C:/Temp/toto/ => C:/Temp
    QString outputFileExtension;
    QString inputFileExtension;
    QString outputBasename;
    bool takeIntoConsiderationForTimeCalculation;

    int sizeInKO;
    QString size;
    QSet<int> dependanceList;
    QString fps;
    bool alreadyCounted;
    bool askUserForInputMsgDone;
    QString duration;
    int length;
    int outputFileVideoBitrate;
    int outputFileAudioBitrate;
    QString vbitrate;
    QString abitrate;
    QString vcodec;
    QString acodec;
    QString errMsgInfo;
    QString errMsgEnc;
    QString stdMsgEnc;
    QString appendToCmdLine;
    QString strFilesize;
    QString strContainer;
    QString frameFile;
    QString overwrite;
    QString prefix;
    QString suffix;
    QProcess::ExitStatus exitStatus;


    bool changeCmdLine;
    QList<QString*> listCommand;

    // The dest filename witch with depends, it's means that we should not start the encoding
    // of the CVideoFile until the video file with the destfile = to dependingOn is not finished
    QString dependance;

    CProfile *profile;
    double percentageDone;
    QComboBox *profileComboBox;
    QListWidget *videoFileListProfileInCombo;
    bool newProgressBarCreated;
    int exitCode;
    int durationSeconde;
    int numberOfPassAlreadydone;
    int sendedToProgressBar;
    int height;
    bool durationSendedToProgressBar;
    int width;
    int *CPU;
    int state;
    int pid;
    QTime EncodingStartedTime;
    int elapsed; // number of millisecond since the start of encoding

    bool endedSuccessfully();
    bool setBitrate(QString);

    bool setCPU(int);
    bool setDestFileName(void);
    bool setFileName();
    void buildCommand(QString, QString, QString, QString,QHash<QString,QString> *);
    QString basenameToView(void);
    void updatePercentageDone(double);
    QString qSetToString(char,int);
    void stringToQSet(QString,char,int);
    void replaceInCmd(QString *);

};

#endif // VIDEOFILE_H
